package com.hzhanghuan.widget.banner.sample;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.hzhanghuan.widget.banner.Banner;
import com.hzhanghuan.widget.banner.BannerIndicator;
import com.hzhanghuan.widget.banner.IndicatorDrawer;
import com.hzhanghuan.widget.banner.Scroller;

/**
 * Created by Administrator on 2016/4/13.
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Banner banner = (Banner) findViewById(R.id.banner);
        banner.setIndicatorGravity(Banner.BOTTOM_RIGHT);
        banner.setIndicatorDrawer(new IndicatorDrawer() {

            @Override
            public void onStandardDraw(Canvas canvas, int left, int top, int right, int bottom, Paint paint) {
                paint.setColor(Color.BLACK);
                canvas.drawRect(left, top + 5, right, bottom - 5, paint);
            }


            @Override
            public void onActiveDraw(Canvas canvas, int left, int top, int right, int bottom, Paint paint) {
                paint.setColor(Color.MAGENTA);
                canvas.drawRect(left, top - 2, right, bottom - 2, paint);
            }
        });
        banner.setBannerPagerAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return 3;
            }


            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }


            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                TextView textView = new TextView(container.getContext());
                container.addView(textView);
                textView.setGravity(Gravity.CENTER);
                textView.setText("" + position);
                return textView;
            }


            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                View view = (View) object;
                container.removeView(view);
            }
        });
        Scroller scroller=new Scroller();
        scroller.setup(banner);

    }
}
